// 316
#[test]
fn test_string_op() {
    let s = String::from("bcabc");
    let mut stack: Vec<char> = Vec::new();
    let mut inStack = [false; 26];
    // 可以使用这个记录字符串中字符出现的最后位置
    // let last = s.as_bytes().iter().enumerate().fold([0; 26], |mut acc, (i, &u)| {
    //     acc[(u - b'a') as usize] = i;
    //     acc
    // });
    for (i, c) in s.chars().enumerate() {
        // println!("{}", c as usize - 'a' as usize);
        // println!("{}", c as char)
        if inStack[c as usize - 'a' as usize] {
            continue;
        }
        while stack.len() > 0 && stack[stack.len()-1] > c && s[i..s.len()].contains(stack[stack.len()-1]) {
            inStack[stack[stack.len()-1] as usize - 'a' as usize] = false;
            stack.pop();
        }
        stack.push(c);
        inStack[c as usize - 'a' as usize] = true;
    }

    // let res = String::from_iter(stack.iter());
    // let mut res = String::new();
    // for c in stack {
    //     res.push(c);
    // }
    let res: String = stack.iter().collect();
    println!("{:?}", res);
}